package com.glc.hms.system.controller.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.glc.hms.common.controller.BaseController;
import com.glc.hms.common.data.ResponseData;
import com.glc.hms.common.data.SuccessResponseData;
import com.glc.hms.common.page.PageFactory;
import com.glc.hms.common.page.PageVo;
import com.glc.hms.core.annotation.SysLogAnno;
import com.glc.hms.system.entity.SysRole;
import com.glc.hms.system.model.param.UpdateRoleMenuParam;
import com.glc.hms.system.model.wrapper.RoleWrapper;
import com.glc.hms.system.service.ISysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author Santa
 * @since 2019/11/28
 */
@Slf4j
@Api(value = "角色", description = "角色接口", basePath = "/webApi/role")
@RestController
@RequestMapping("/webApi/role")
public class RoleController extends BaseController {


    @Autowired
    private ISysRoleService roleService;

    /**
     * 获取角色列表
     */
    @ApiOperation(value = "获取角色列表", response = ResponseData.class)
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    //@Permission({"admin"})//管理员才能作此操作
    public ResponseData getUser() {
        Page<Map<String, Object>> mapPage = roleService.queryRoleByPage();
        Page wrap = new RoleWrapper(mapPage).wrap();
        PageVo pageInfo = PageFactory.createPageInfo(wrap);
        return new SuccessResponseData(pageInfo);
    }

    /**
     * 修改角色
     */
    @ApiOperation(value = "修改角色", response = ResponseData.class)
    @RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)
    @SysLogAnno(value = "修改角色")
    //@Permission({"admin"})//管理员才能作此操作
    public ResponseData saveOrUpdate(@RequestBody SysRole sysRole) {
        roleService.saveOrUpdate(sysRole);
        return SUCCESS_TIP;
    }

    /**
     * 修改角色权限菜单
     */
    @ApiOperation(value = "修改角色权限菜单", response = ResponseData.class)
    @RequestMapping(value = "/updateMenu", method = RequestMethod.POST)
    @SysLogAnno(value = "修改角色权限菜单")
    //@Permission({"admin"})//管理员才能作此操作
    public ResponseData updateMenu(@RequestBody UpdateRoleMenuParam updateRoleMenuParam) {
        roleService.updateRoleMenu(updateRoleMenuParam);
        return SUCCESS_TIP;
    }

    /**
     * 删除角色
     */
    @ApiOperation(value = "删除角色", response = ResponseData.class)
    @RequestMapping(value = "/delRole", method = RequestMethod.GET)
    @SysLogAnno(value = "删除角色")
    //@Permission({"admin"})//管理员才能作此操作
    public ResponseData delUser(@ApiParam(name = "roleId", value = "角色id", required = true) Long roleId) {
        roleService.delUserRole(roleId);
        return SUCCESS_TIP;
    }
}























